class Solution:
def minDistance(self, word1: str, word2: str) -> int:
if not word1 and not word2:
return 0
if word1 == word2:
return 0
dp = []
for i in range(len(word1)+1):
a = []
for j in range(len(word2)+1):
a.append(0)
dp.append(a)
for i in range(len(word1)+1):
dp[i][0] = i
for i in range(len(word2) +1):
dp[0][i] = i
for i in range(1, len(word1)+1, 1):
for j in range(1, len(word2)+1, 1):
if word1[i-1] == word2[j-1]:
dp[i][j] = dp[i-1][j-1]
else:
dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1
return dp[-1][-1]
Partitioning binary strings | Special sets |
Smallest chosen word | Going to office |
Color the boxes | Missing numbers |
Maximum sum | 13 Reasons Why |
Friend's Relationship | Health of a person |
Divisibility | A. Movement |
Numbers in a matrix | Sequences |
Split houses | Divisible |
Three primes | Coprimes |
Cost of balloons | One String No Trouble |
Help Jarvis! | Lift queries |
Goki and his breakup | Ali and Helping innocent people |
Book of Potion making | Duration |
Birthday Party | e-maze-in |
Bricks Game | Char Sum |